package com.movisol.tools.solvers;

import java.util.Iterator;
import java.util.List;

import com.movisol.questionwizard.entities.ChoiceButtonImageQuestion;
import com.movisol.questionwizard.entities.ChoiceImageQuestion;
import com.movisol.questionwizard.entities.ChoiceImageScrollQuestion;
import com.movisol.questionwizard.entities.ChoiceQuestion;
import com.movisol.questionwizard.entities.Question;
import com.movisol.questionwizard.entities.QuestionType;

public class GenericSolver implements GenericSolverInterface {
	
	List<Question> questionList = null;
	
	public GenericSolver(List<Question> list)
	{
		questionList = list;
	}

	@Override
	public Integer calculateResult() {
		Iterator<Question> it = questionList.iterator();	
		int result = 0;


		while (it.hasNext()) 
		{
			Question actualQuestion = (Question) it.next();
			int value = 0;
			
			switch(actualQuestion.getType().getType())
			{
				case QuestionType.CHOICE:
					value = Integer.valueOf( ((ChoiceQuestion)actualQuestion).getSelectedValue().getValue());
				break;
				case QuestionType.CHOICEBUTTONIMAGE:
					value = Integer.valueOf( ((ChoiceButtonImageQuestion)actualQuestion).getSelectedValue().getValue());
				break;
				case QuestionType.CHOICEIMAGE:
					value = Integer.valueOf( ((ChoiceImageQuestion)actualQuestion).getSelectedValue().getValue());
				break;
				case QuestionType.CHOICEIMAGESCROLL:
					value = Integer.valueOf( ((ChoiceImageScrollQuestion)actualQuestion).getSelectedValue().getValue());
				break;
				default:
					value = 0;
				break;
			
			}
			
			
			result+=value;
		}

				
		return result;
	}
	

}
